home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / sccs.arc / HDIFF.DOC < prev    next >
Text File  |  1985-12-10  |  15KB  |  352 lines

  1.                                19 February, 1984
  2.  
  3.                   hdiff 1.14
  4.  
  5.        Purpose
  6.        -------
  7.  
  8.        hdiff is a utility which can compare two standard DOS text files
  9.        and isolate the differences between them.  It can produce two
  10.        distinct types of reports on the differences.  First, hdiff can
  11.        prepare a simple report of lines which appear in the second file
  12.        but not in the first (insertions), and of lines which appear in
  13.        the first file but not in the second (deletions).  Second, hdiff
  14.        can produce a special "report" which is, in fact, an Edlin
  15.        script.    This script, when applied to the first file, will
  16.        produce a clone of the second file.  This second function of
  17.        hdiff is similar to the Unix utility "diff".
  18.  
  19.        hdiff uses a file comparison algorithm which was developed by
  20.        Paul Heckel and described by D.E.Cortesi in Dr. Dobb's Journal
  21.        #94 (August, 1984).  The algorithm is substantially more
  22.        efficient than traditional file comparison methods; you will find
  23.        that it can generate a difference report between two files in
  24.        little more than the time it takes to read the two files.
  25.  
  26.        This version of hdiff was derived from Cortesi's demonstration
  27.        program, with substantial modifications which
  28.  
  29.        -- accomodate differences between Edlin and CP/M's Ed (for which
  30.        the demo was written)
  31.        -- allow use of Edlin's block move capabilities
  32.        -- allow for much larger files through the use of all available
  33.        memory.
  34.        -- allow the use of command line parameters and switches,
  35.        including case and spacing insensitivity.
  36.        -- allow the user to specify at run time the maximum number of
  37.        lines which will be processed.  This allows hdiff to use memory
  38.        more efficiently.
  39.        -- allow the user to request the simpler difference report rather
  40.        than the Edlin script.
  41.  
  42.  
  43.        System requirements
  44.        -------------------
  45.  
  46.        hdiff requires:
  47.  
  48.        -- IBM PC, PC/XT, PC/AT, or other MSDOS machine
  49.        -- MSDOS 2.00 or later
  50.        -- At least 128K of RAM.  The more RAM you have, the larger the
  51.        files you can process.
  52.  
  53.  
  54.        Running hdiff
  55.        -------------
  56.  
  57.        The general syntax for hdiff is:
  58.  
  59.         hdiff [-ecs] [-nnnn] oldfile.ext newfile.ext
  60.  
  61.        The optional -e switch instructs hdiff to produce an Edlin script
  62.        file rather than the difference report.
  63.  
  64.        The optional -c switch instructs hdiff to ignore differences in
  65.        case: "HDIFF" is the same as "hdiff".
  66.  
  67.        The optional -s switch instructs hdiff to ignore differences in
  68.        spacing; all spaces and tabs are ignored for comparison purposes.
  69.  
  70.        The optional -nnnn switch assists in memory management; it
  71.        represents the maximum number of lines hdiff will be required to
  72.        process, i.e., the number of lines in the larger of the two
  73.        files.  The default for this value is 2000 lines; there is an
  74.        absolute maximum of 5000 lines.    See the section on memory
  75.        management for more information about this switch.
  76.  
  77.        The switches may be combined, and they may be in any order: '-e
  78.        -c -1000', '-1000ce', and '-ce1000' are all equivalent.
  79.  
  80.        Examples:
  81.  
  82.         hdiff foo.c newfoo.c
  83.  
  84.        compares file 'foo.c' with file 'newfoo.c' and produces a simple
  85.        report showing insertions (lines in newfoo which do not appear in
  86.        foo) and deletions (lines in foo which do not appear in newfoo).
  87.        Lines which have been moved but are otherwise unchanged do not
  88.        appear in this report.
  89.  
  90.         hdiff -ec foo.c newfoo.c
  91.  
  92.        compares foo.c with newfoo.c, ignoring case differences, and
  93.        prepares an Edlin script.  This script, if applied to foo, will
  94.        create a copy of newfoo.  The script file is sent to the console,
  95.        so a more useful command is
  96.  
  97.         hdiff -e foo.c newfoo.c > foo.dat
  98.  
  99.        which uses standard DOS redirection to send the edlin script to
  100.        the disk file foo.dat.  Note that the program logo and error
  101.        messages are unaffected by redirection and will always be sent to
  102.        the screen.
  103.  
  104.         hdiff -e4000 foo.c newfoo.c > foo.dat
  105.  
  106.        is equivalent to the previous command, except that it informs
  107.        hdiff that one of the files might contain up to 4000 lines.
  108.  
  109.  
  110.        Report formats
  111.        --------------
  112.  
  113.        The difference report consists of lines in the format:
  114.  
  115.         nnnn+ text
  116.        or
  117.         nnnn- text
  118.  
  119.        The '+' format indicates that the line is new (an insertion); the
  120.        '-' format indicates that the line is gone (a deletion).  Thus:
  121.  
  122.         0001- This line appears in the old file only
  123.         0001+ This line appears in the new file only
  124.  
  125.        The 'nnnn' represents the line number.  For '+' lines, it's the
  126.        line number in the new file; for '-' lines, it's the line number
  127.        in the old file.
  128.  
  129.        The Edlin script is a series of Edlin commands.    See Edlin
  130.        documentation for their meanings; the only commands which will
  131.        appear are I (insert), D (delete), M (move), and E (End).  The
  132.        script may look a little strange if you look at it (with an
  133.        editor or via the TYPE command).  After the completion of each
  134.        insertion sequence, there will be a heart symbol; this is the
  135.        screen representation of Ctrl-C, which is used to terminate an
  136.        Edlin insertion.
  137.  
  138.  
  139.        Uses
  140.        ----
  141.  
  142.        The simplest use for hdiff is to compare two files to see if they
  143.        are the same.  This can be used to check for corruption during
  144.        backups, copies, etc., or to determine which of two files is
  145.        newer.  Even this simple use of hdiff can be useful in unexpected
  146.        ways, however.  For example, look at this small batch file:
  147.  
  148.         dir a: > temp
  149.         find "-" temp > dir.a
  150.         dir b: > temp
  151.         find "-" temp > dir.b
  152.         hdiff dir.b dir.a > temp.bat
  153.         erase dir.a
  154.         erase dir.b
  155.         erase temp
  156.  
  157.        This batch can be used for a simple backup system.  Assume that
  158.        the default directory in drive A contains a series of files that
  159.        you want to backup, and that the default directory in drive B
  160.        contains the same set of files from the last backup.  The batch
  161.        will isolate differences between the two directories and prepare
  162.        a file called temp.bat which contains a list of those files which
  163.        have been changed or added since the last backup.  (The .bat
  164.        extension is used because many popular text editors could very
  165.        easily convert the temp.bat file to a series of copy commands
  166.        which could be used, in batch mode, to perform the copying.)
  167.  
  168.        The "Edlin" mode has potentially much more significant use.
  169.        Perhaps its greatest potential lies in what are known as "source
  170.        code control systems".  These systems, quite common in mainframe
  171.        and minicomputer systems, allow programmers to maintain many
  172.        generations of program source text quite economically; rather
  173.        than storing each modified file in its entirety, only the
  174.        original is saved, along with a series of difference files.
  175.  
  176.        Hdiff provides a first step in this direction for MSDOS machines
  177.        (see the "Plans" section below).  Typical use of the current
  178.        hdiff would be something like this.  Assume that hdiff.scc
  179.        contains an "original" version of hdiff; the current version
  180.        (1.10) is hdiff.c.  First, the command
  181.  
  182.         hdiff -e hdiff.scc hdiff.c > hdiff.110
  183.  
  184.        will create an edlin script which would convert hdiff.scc into
  185.        version 1.10 of hdiff.c.  Typically, the actual hdiff.c file
  186.        would them be discarded (WARNING: see below.  This program is
  187.        experimental!)  As newer versions are developed, the same
  188.        procedure is used to create hdiff.111, hdiff.120, etc.  Note that
  189.        these difference files would, in all likelihood, be much smaller
  190.        that the total size of all of the versions.
  191.  
  192.        In order to "retrieve" an earlier version, say 1.00, the command
  193.  
  194.         copy hdiff.scc hdiff.c
  195.         edlin hdiff.c < hdiff.100
  196.  
  197.        would convert hdiff.scc into version 1.00 of hdiff.
  198.  
  199.        True source code control systems are considerably more efficient
  200.        than this "by hand" method, are much easier to use, and provide
  201.        significant features beyond mere storage of multiple versions.
  202.  
  203.        For whatever it's worth, note that
  204.  
  205.         hdiff -e file1 file2 | edlin file1
  206.  
  207.        is roughly equivalent to
  208.  
  209.         copy file2 file1
  210.  
  211.        except that the original file1 is saved in file1.bak.
  212.  
  213.  
  214.        cdelta and cget
  215.        ---------------
  216.  
  217.        The two demonstration batches, cdelta and cget, provide a quick
  218.        sample of the kinds of things that can be done with hdiff and
  219.        edlin.  The two batches are designed for C programs; to revise
  220.        them for other languages, simply replace all references to ".c"
  221.        with the desired extension (.asm, for example).
  222.  
  223.        The purpose of cdelta is to generate a change script which will
  224.        convert a "base" source file into a specified version of your
  225.        source.    Cget performs the inverse task; it applies a specified
  226.        change file to the base and produces a file containing the
  227.        specified version.  File naming conventions are as follows:
  228.  
  229.         file.scc:    "base" source; scc = source code control
  230.         file.###:    A change script to produce version ###
  231.         file.c:      The current version (cdelta), or the
  232.                  output file (cget)
  233.  
  234.        For example, suppose you are working with a C program called foo.
  235.        A base (earliest) version of this file should be in foo.scc.  You
  236.        have just finished revision 1.10 of foo.  To create the change
  237.        file, type
  238.  
  239.         cdelta foo 110
  240.  
  241.        The batch will create a new file, foo.110; this file is an Edlin
  242.        script which will convert foo.scc into version 1.10 of foo.c.
  243.  
  244.        To retrieve a specified version, say 1.05, use
  245.  
  246.         cget foo 105
  247.  
  248.        The batch will apply the script foo.105 to foo.scc and produce
  249.        foo.c, which will contain the source for version 1.05.
  250.  
  251.        Note that cget always creates a file called file.c, overwriting
  252.        any existing file by that name.    This implies that you do NOT
  253.        keep your current source in file.c; you keep the current source
  254.        only by retaining file.scc and the delta files.
  255.  
  256.  
  257.        Memory management
  258.        -----------------
  259.  
  260.        Hdiff uses all available memory.  The purpose of the -nnnn (max
  261.        number of lines) switch is to allow it to use memory more
  262.        efficiently, and to allow you to more effectively use hdiff in
  263.        very small or very large machines.  This is how it works.
  264.  
  265.        For each *potential* line, hdiff requires approximately 34 bytes
  266.        of storage for various tables.  The default configuration (space
  267.        for 2000 lines) will thus require about 68K bytes of data space
  268.        for the tables.    The remainder of available memory (less the size
  269.        of the program itself and a much smaller amount of overhead data)
  270.        is used to store the text read from the files.  Text storage
  271.        space is required for each *unique* line in either file.
  272.  
  273.        If you have a small machine (i.e., less RAM), that much table
  274.        space will leave very little room for text storage; it may even
  275.        be more space than is available, and the program will not run at
  276.        all.  If you find this to be the case, try reducing the number of
  277.        lines via the switch (-1000, or -500, for example.)
  278.  
  279.        Conversely, if you have a very large machine, you will have
  280.        plenty of space available to process file larger than 2000 lines.
  281.        If that is the case, increase the maxlines switch as necessary
  282.        (but remember that in no case can maxlines exceed 5000).
  283.  
  284.        When hdiff is finished, it displays a message like:
  285.  
  286.         Storage use: 19%
  287.  
  288.        This message tells you approximately what percentage of the total
  289.        available memory was actually used.
  290.  
  291.  
  292.        Restrictions
  293.        ------------
  294.  
  295.        The following act, in one way or another, as restrictions on
  296.        hdiff:
  297.  
  298.        -- File format.    Hdiff is intended as a DOS text file comparator
  299.        only.  It is NOT a replacement for the DOS utility 'comp'.  Don't
  300.        use it on binary (program or data) files, or on word processor
  301.        files if they contain embedded control codes.
  302.        -- Available memory (as discussed above)
  303.        -- Actual size of the files. Edlin will read a file only until
  304.        75% of its available memory is filled.  Since Edlin uses only a
  305.        maximum of 64K, this means that it will read only 48K of text.
  306.        Hdiff cannot account for this problem, so the absolute maximum
  307.        file size it can handle is approximately 48K.
  308.        -- Line size.  Limited to a maximum of 255 characters/line.
  309.  
  310.  
  311.        A Warning and A Plan
  312.        --------------------
  313.  
  314.        Hdiff is experimental!  It has been in use for about six months
  315.        (as of 19 Feb 1985) with no known errors, but this is is NOT to
  316.        say that you should entrust your only copy of a source file to
  317.        hdiff!  Please bear this in mind as you use it.    Please report
  318.        any problems to me.
  319.  
  320.        I intend, at some "unspecified future time", to incorporate hdiff
  321.        or a version of it in a larger source code control system.  This
  322.        system would allow you to maintain multiple generations of
  323.        program source files very efficiently (in terms of storage
  324.        requirements).  Some knotty problems relating to performance on a
  325.        standard-issue PC remain to be solved.  Comments or suggestions
  326.        relating to this system are welcome.  Tell me what you would like
  327.        to see.    In the meantime, a temporary "system" is avilable in the
  328.        file "sccs.lbr", which contains simple versions of get and delta
  329.        (written in C for performance reasons).
  330.  
  331.  
  332.  
  333.                 ---------------------
  334.  
  335.              hdiff and this document are
  336.              Copyright (c) 1984, 1985 by:
  337.  
  338.                 Christopher J. Dunford
  339.                10057-2 Windstream Drive
  340.                Columbia, Maryland 21044
  341.                 CompuServe 76703,2002
  342.                 Source STR211
  343.  
  344.        You may copy and use hdiff for your personal use only.  You may
  345.        copy hdiff for others, but you may not charge them for it.  You
  346.        may not use hdiff for any commercial purpose whatsoever.  Address
  347.        comments to the author at the above address, at CompuServe
  348.        (preferably) or at the Source (occasionally).
  349.  
  350.        Hdiff is written in C and compiled using the Computer Innovations
  351.        C86 compiler (Version 2.13), large model.
  352.